package solutions.leetcode.easy

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/decode-the-message/">2325. 解密消息</a>
 */
private class Solution2325 {
    fun decodeMessage(key: String, message: String): String {
        val d = CharArray(26) { ' ' }
        var t = 'a'
        for (item in key) {
            if (item == ' ') {
                continue
            }
            if (d[item - 'a'] == ' ') {
                d[item - 'a'] = t
                t++
            }
        }
        val sb = StringBuilder()
        for (item in message) {
            if (item == ' ') {
                sb.append(' ')
            } else {
                sb.append(d[item - 'a'])
            }
        }
        return sb.toString()
    }
}

fun main() {
    println(Solution2325().decodeMessage("the quick brown fox jumps over the lazy dog", "vkbs bs t suepuv"))
}